$(function() {
	// 校验产品ID
	$("#Form").validate({
		rules : {
			productId : {
				required : true,
				remote : {
					url : "financePro/checkFinanceId",
					type : "GET"
				}
			},
		},
		messages : {
			productId : {
				//required : "请输入产品ID",
				remote : "产品ID已经存在"
			},
		},
		errorClass : "red"
	});
});
String.prototype.trim = function() {
		return this.replace(/^\s+/, "").replace(/\s+$/, "");
	}
	function trim() {

	}

	var falg = false;

	function checkProdsId(ProdId) {
		ProdId = ProdId.trim();
		var productidSp = document.getElementById("productidSp");
		if (ProdId != "") {
			return falg = true;
		} else {
			productidSp.innerHTML = "<font style='color:#DD5A43;font-size:14px;'>请输入产品ID</font>";
			return falg = false;
		}
	}
	function checkProdIdsError() {
		var productidSp = document.getElementById("productidSp");
		productidSp.innerHTML = "";
	}
	/* 产品名称 */
	function checkProdName(ProdName) {
		ProdName = ProdName.trim();
		var productNaSp = document.getElementById("productNaSp");
		if (ProdName != "") {
			return falg = true;
		} else {
			productNaSp.innerHTML = "<font style='color:#DD5A43;font-size:14px;'>请输入产品名称</font>";
			return falg = false;
		}
	}
	function checkProdNameError() {
		var productSp = document.getElementById("productNaSp");
		productNaSp.innerHTML = "";
	}
	/* 年利率 */
	function checkProdRate(ProdRate) {
		ProdRate = ProdRate.trim();
		var productRaSp = document.getElementById("productRaSp");
		var ProdRateExp = /^\d+(\.\d+)?$/;
		if (ProdRate != "") {
			var ProdRateE = ProdRateExp.test(ProdRate);
			if (ProdRateE) {
				return falg = true;
			} else {
				productRaSp.innerHTML = "<font style='color:#DD5A43;font-size:14px;'>年利率必须为正浮点型</font>";
			}

		} else {
			productRaSp.innerHTML = "<font style='color:#DD5A43;font-size:14px;'>年利率不能为空</font>";
		}
	}
	function checkProdRateError() {
		var productRaSp = document.getElementById("productRaSp");
		productRaSp.innerHTML = "";
	}
	/* 募集天数 */
	function checkProdCollectDay(ProdCollectDay) {
		ProdCollectDay = ProdCollectDay.trim();
		var productCoSp = document.getElementById("productCoSp");
		var ProdCollectDayExp = /^\d+$/;
		if (ProdCollectDay != "") {
			var ProdCollectDayE = ProdCollectDayExp.test(ProdCollectDay);
			if (ProdCollectDayE) {
				return falg = true;
			} else {
				productCoSp.innerHTML = "<font style='color:#DD5A43;font-size:14px;'>募集天数必须为正整数</font>";
			}
		} else {
			productCoSp.innerHTML = "<font style='color:#DD5A43;font-size:14px;'>募集天数不能为空</font>";
		}
	}
	function checkProdCollectDayError() {
		var productCoSp = document.getElementById("productCoSp");
		productCoSp.innerHTML = "";
	}
	/* 理财期限 */
	function checkProdDuration(ProdDuration) {
		ProdDuration = ProdDuration.trim();
		var productDuSp = document.getElementById("productDuSp");
		var productDuSpExp = /^\d+$/;
		if (ProdDuration != "") {
			var productDuSpE = productDuSpExp.test(ProdDuration);
			if (productDuSpE) {
				return falg = true;
			} else {
				productDuSp.innerHTML = "<font style='color:#DD5A43;font-size:14px;'>理财天数必须为正整数</font>";
			}
		} else {
			productDuSp.innerHTML = "<font style='color:#DD5A43;font-size:14px;'>理财天数不能为空</font>";
		}
	}
	function checkProdDurationError() {
		var productDuSp = document.getElementById("productDuSp");
		productDuSp.innerHTML = "";
	}
	/* 起投金额 */
	function checkProdMin(ProdMin) {
		ProdMin = ProdMin.trim();
		var productMiSp = document.getElementById("productMiSp");
		var productMiSpExp = /^\d+(\.\d+)?$/;
		if (ProdMin != "") {
			var productMiSpE = productMiSpExp.test(ProdMin);
			if (productMiSpE) {
				return falg = true;
			} else {
				productMiSp.innerHTML = "<font style='color:#DD5A43;font-size:14px;'>起投金额必须为正浮点型</font>";
			}

		} else {
			productMiSp.innerHTML = "<font style='color:#DD5A43;font-size:14px;'>起投金额不能为空</font>";
		}
	}
	function checkProdMinError() {
		var productMiSp = document.getElementById("productMiSp");
		productMiSp.innerHTML = "";
	}
	/* 投资上限 */
	function checkProdMax(ProdMax) {
		ProdMax = ProdMax.trim();
		var productMaSp = document.getElementById("productMaSp");
		var productMaSpExp = /^\d+(\.\d+)?$/;
		if (ProdMax != "") {
			var productMaSpE = productMaSpExp.test(ProdMax);
			if (productMaSpE) {
				return falg = true;
			} else {
				productMaSp.innerHTML = "<font style='color:#DD5A43;font-size:14px;'>投资上限金额必须为正浮点型</font>";
			}

		} else {
			productMaSp.innerHTML = "<font style='color:#DD5A43;font-size:14px;'>投资上限金额不能为空</font>";
		}
	}
	function checkProdMaxError() {
		var productMaSp = document.getElementById("productMaSp");
		productMaSp.innerHTML = "";
	}

	/* 提交 */
	function buttAdd() {
		var productId = document.getElementById("productId").value
		var ProdName = document.getElementById("productName").value
		var ProdRate = document.getElementById("rate").value
		var ProdCollectDay = document.getElementById("collectDay").value
		var ProdDuration = document.getElementById("duration").value
		var ProdMin = document.getElementById("minInvestAmount").value
		var ProdMax = document.getElementById("maxInvestAmount").value

		var productId = checkProdsId(productId);/* 产品ID */
		var ProdName = checkProdName(ProdName);/* 产品名称 */
		var ProdRate = checkProdRate(ProdRate);/* 年利率 */
		var ProdCollectDay = checkProdCollectDay(ProdCollectDay)/* 募集天数 */
		var ProdDuration = checkProdDuration(ProdDuration)/* 理财期限 */
		var ProdMin = checkProdMin(ProdMin)/* 起投金额 */
		var ProdMax = checkProdMax(ProdMax)/* 投资上限 */
		if (productId && ProdName && ProdRate && ProdCollectDay && ProdDuration
				&& ProdMin && ProdMax) {
			document.forms["Form"].submit();
			document.forms["Form"].method = "get";
		}
	}